package com.rory.gooday.blog;

import com.rory.gooday.common.model.Blog;
import com.rory.gooday.common.model.BlogCol;
import com.rory.gooday.common.model.BlogColRel;
import com.jfinal.plugin.activerecord.Page;

public class BlogService {

	private final Blog blogDao = new Blog().dao();

	private final BlogCol blogColDao = new BlogCol().dao();

	private final BlogColRel blogColRelDao = new BlogColRel().dao();
	
	public Page<Blog> paginate(int pageNumber, int pageSize) {
		Page<Blog> b = blogDao.paginate(pageNumber, pageSize, "SELECT blog.*, blog_show.is_show as 'is_show'", "FROM blog LEFT JOIN blog_show ON blog.ucode = blog_show.ucode WHERE blog_show.id IS NOT NULL order by blog_show.id desc");
		return b;
	}
	
	public Blog findById(int id) {
		return blogDao.findFirst("SELECT blog.*, blog_show.is_show as 'is_show' FROM blog LEFT JOIN blog_show ON blog.ucode = blog_show.ucode WHERE blog.id = "+id+" order by blog_show.id desc" );
	}

	public void deleteById(int id) {
		blogDao.deleteById(id);
	}
}
